using System;
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;
using UnityEngine.PlayerLoop;
using UnityEngine.UI;

public class ChangeCharacter : MonoBehaviour
{
    public GameObject Saber;
    public GameObject Archer;
    public GameObject Mage;
    public Skill_List SkillListSaber;
    public Skill_List SkillListArcher;
    public Skill_List SkillListMage;

    private Image saberIcon;
    private Image archerIcon;
    private Image mageIcon;

    public GameObject saberUI;
    public GameObject archerUI;
    public GameObject mageUI;
    private void Update()
    {
        if (Saber == null|| Archer==null|| Mage==null)
        {
            Saber = GameManager.Instance.saber;
            Archer = GameManager.Instance.archer;
            Mage = GameManager.Instance.mage;
            saberIcon = transform.GetChild(0).GetComponent<Image>();
            archerIcon = transform.GetChild(1).GetComponent<Image>();
            mageIcon = transform.GetChild(2).GetComponent<Image>();
            
            UseSaber();
        }
    }


    public void UseNoBody()
    {
        if (Saber.activeSelf == true)
        {
            Saber.SetActive(false);
        }
        else if (Archer.activeSelf == true)
        {
            Archer.SetActive(false);
        }
        if (Mage.activeSelf == true)
        {
            Mage.SetActive(false);
        }
        
        transform.GetChild(0).GetComponent<RectTransform>().sizeDelta = new Vector2(70, 70);
        transform.GetChild(1).GetComponent<RectTransform>().sizeDelta = new Vector2(70, 70);
        transform.GetChild(2).GetComponent<RectTransform>().sizeDelta = new Vector2(70, 70);
        saberIcon.color = new Color(saberIcon.color.r, saberIcon.color.g, saberIcon.color.b, 100/255f);
        archerIcon.color = new Color(archerIcon.color.r, archerIcon.color.g, archerIcon.color.b, 100/255f);
        mageIcon.color = new Color(mageIcon.color.r, mageIcon.color.g, mageIcon.color.b, 100/255f);
    }
    
    
    public void UseSaber()
    {
        Saber.transform.position = GameManager.Instance.playerStats.gameObject.transform.position;
        Saber.transform.rotation = GameManager.Instance.playerStats.gameObject.transform.rotation;
        UseNoBody();
        Saber.SetActive(true);
        GameManager.Instance.playerStats.characterData.characterType =CharacterType.Saber;
        InventoryManager.Instance.SkillData = SkillListSaber;
        InventoryManager.Instance.skillUI.RefreshUI();
        transform.GetChild(0).GetComponent<RectTransform>().sizeDelta = new Vector2(100, 100);
        saberIcon.color = new Color(saberIcon.color.r, saberIcon.color.g, saberIcon.color.b, 1f);
    }
    
    public void UseArcher()
    {
        Archer.transform.position = GameManager.Instance.playerStats.gameObject.transform.position;
        Archer.transform.rotation = GameManager.Instance.playerStats.gameObject.transform.rotation;
        UseNoBody();
        Archer.SetActive(true);
        GameManager.Instance.playerStats.characterData.characterType =CharacterType.Archer;
        InventoryManager.Instance.SkillData = SkillListArcher;
        InventoryManager.Instance.skillUI.RefreshUI();
        transform.GetChild(1).GetComponent<RectTransform>().sizeDelta = new Vector2(100, 100);
        archerIcon.color = new Color(archerIcon.color.r, archerIcon.color.g, archerIcon.color.b, 1f);
    }
    
    public void UseMage()
    {
        Mage.transform.position = GameManager.Instance.playerStats.gameObject.transform.position;
        Mage.transform.rotation = GameManager.Instance.playerStats.gameObject.transform.rotation;
        UseNoBody();
        Mage.SetActive(true);
        GameManager.Instance.playerStats.characterData.characterType =CharacterType.Mage;
        InventoryManager.Instance.SkillData = SkillListMage;
        InventoryManager.Instance.skillUI.RefreshUI();
        transform.GetChild(2).GetComponent<RectTransform>().sizeDelta = new Vector2(100, 100);
        mageIcon.color = new Color(mageIcon.color.r, mageIcon.color.g, mageIcon.color.b, 1f);
    }
}
